﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityNpcSpawnData.h
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-29
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityNpcSpawnData
//    @Desc             :
//
// -------------------------------------------------------------------------

#pragma once

#include "E_NpcBase.nanopb.h"
#include "NpcBaseDescEx.h"
#include "NFComm/NFShmStl/NFShmHashSet.h"
#include "NFLogicCommon/NFBaseDefine.h"
#include "NFLogicCommon/NFCommMacros.h"



class NFCityNpcSpawnData
{
public:
    NFCityNpcSpawnData();
    ~NFCityNpcSpawnData();
    int CreateInit();
    int ResumeInit();

public:
    int Init(int iMapInstID, int iSpawnId);
    void Tick();

    int GetSpawnId() const { return m_iSpawnId; }
    int OnRemoveNpc(int iNpcGid, int iLocationId, int iNpcId);

    int RefreshAllNpc(int iLeftTime);
    int Spawn(int iSpawnEndTime);

private:
    bool IsNeedReflush();
    bool IsInSpawnPeriod(int& iSpawnEndTime);

    int RandNpc(const E_NpcSpawn* pstSpawnDesc);
    int RandLocation(int locationGroupId);

    int AddNpcGid(int iNpcGid);
    int DelNpcGid(int iNpcGid);

private:
    int m_iMapInstID;
    int m_iSpawnId; //spawn id
    int m_iInterval;

    NFShmHashSet<int32_t, MAX_LOCATION_NUM> m_bLocationIdMap;
    bool m_bEventTrigger;

    NFShmHashSet<int32_t, MAX_NPC_GROUP_RECORD_NUM> m_bNpcIdMap;
    NFShmHashSet<int32_t, MAX_NPC_GROUP_RECORD_NUM> m_aiNpcGid;

    int m_iLastSpawnTime;
};
